package com.yibai.web.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yibai.web.app.entity.Website;
import com.yibai.web.app.mapper.WebsiteMapper;
import com.yibai.web.app.service.WebsiteService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yibai.web.dto.SuperResponse;
import com.yibai.web.dto.WebsiteInfoRequest;
import com.yibai.web.dto.WebsiteListRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-04-19
 */
@Service
public class WebsiteServiceImpl extends ServiceImpl<WebsiteMapper, Website> implements WebsiteService {


    @Override
    public SuperResponse list(WebsiteListRequest request) {
        SuperResponse response = new SuperResponse();
        QueryWrapper<Website> wrapper = new QueryWrapper();
        Page<Website> pages = new Page<>(request.getPageNo(),request.getPageSize());
        IPage<Website> mapIPage = baseMapper.selectPage(pages, wrapper);
        List<Website> agents = mapIPage.getRecords();
        response.setItems(agents);
        response.setTotals(pages.getTotal());
        return response;
    }

    @Override
    public SuperResponse update(WebsiteInfoRequest request) {
        SuperResponse response = new SuperResponse();
        Website website = new Website();
        website.setId(request.getId());
        website.setName(request.getName());
        website.setDomain(request.getDomain());
        website.setIconUrl(request.getIconUrl());
        website.setRecordNum(request.getRecordNum());
        website.setSlogan(request.getSlogan());
        website.setFaviconUrl(request.getFaviconUrl());
        website.setStatistical(request.getStatistical());
        website.setStatus(request.getStatus());
        baseMapper.updateById(website);
        return response;
    }
}
